﻿using WS.EKA.DataAccess;
using WS.EKA.Model;
using WS.EKA.ServiceInterface;
using System;
using WS.EKA.Utilities.EncryptTool;
using System.Linq;


namespace WS.EKA.ServiceImpl
{
    public class AccountService : IAccountService
    {
        Reversible encrypt = new Reversible();
        public Account Authentication(Account entity)
        {
            
            string pwd = encrypt.ToMD5(entity.Pwd);
            var account = AccountContext.Get(t => t.MemLoginID == entity.MemLoginID && t.Pwd == pwd);
            return account;
        }

        public int Add(Account entity)
        {
            entity.Pwd = encrypt.ToMD5(entity.Pwd);
            return AccountContext.Add(entity);
        }
        public Account GetByLoginId(string loginid)
        {
            return AccountContext.Get(t => t.MemLoginID == loginid);
        }

        public bool UserExist(string loginId)
        {
            return AccountContext.Get(t => t.MemLoginID == loginId) != null;
        }
    }
}
